////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation.  All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// Ports Copyright (c) 2012 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>

//--//

#define FLASH_BLOCK_COUNT                    2
#define FLASH_BYTES_PER_BLOCK                1024
#define FLASH_BYTES_PER_SECTOR               1024
#define FLASH_SECTOR_WRITE_TYPICAL_TIME_USEC 1400    // not used
#define FLASH_BLOCK_ERASE_ACTUAL_TIME_USEC   1000000 // not used
#define FLASH_BLOCK_ERASE_MAX_TIME_USEC      3000000 // not used

//--//

// EBIU Information

#define FRAM__SIZE_IN_BYTES     FLASH_BLOCK_COUNT * FLASH_BYTES_PER_BLOCK
#define FRAM__WP_GPIO_PIN       GPIO_PIN_NONE
#define FRAM__WP_ACTIVE         FALSE

//--//

// BlockDeviceInformation

#define FRAM__IS_REMOVABLE      FALSE
#define FRAM__SUPPORTS_XIP      FALSE
#define FRAM__WRITE_PROTECTED   FALSE
#define FRAM__SUPP_COPY_BACK    FALSE
#define FRAM__NUM_REGIONS       1

//--//

const BlockRange g_FRAM_BlockRange[] =
{
    { BlockRange::BLOCKTYPE_STORAGE_A,    0,  0 },  // 1K
    { BlockRange::BLOCKTYPE_STORAGE_B,    1,  1 }   // 1K
};

const BlockRegionInfo  g_FRAM_BlkRegion[FRAM__NUM_REGIONS] =
{
    {
        0,                     // ByteAddress  Start;         // Starting Sector address
        FLASH_BLOCK_COUNT,     // UINT32       NumBlocks;     // total number of blocks in this region
        FLASH_BYTES_PER_BLOCK, // UINT32       BytesPerBlock; // Total number of bytes per block
        ARRAYSIZE_CONST_EXPR(g_FRAM_BlockRange),
        g_FRAM_BlockRange,
    }
};

//--//

const BlockDeviceInfo g_FRAM_DeviceInfo=
{
    {  
        FRAM__IS_REMOVABLE,                 // BOOL Removable;
        FRAM__SUPPORTS_XIP,                 // BOOL SupportsXIP;
        FRAM__WRITE_PROTECTED,              // BOOL WriteProtected;
        FRAM__SUPP_COPY_BACK                // BOOL SupportsCopyBack
    },
    FLASH_SECTOR_WRITE_TYPICAL_TIME_USEC,   // UINT32 MaxSectorWrite_uSec;
    FLASH_BLOCK_ERASE_ACTUAL_TIME_USEC,     // UINT32 MaxBlockErase_uSec;
    FLASH_BYTES_PER_SECTOR,                 // UINT32 BytesPerSector;
    FLASH_MEMORY_Size,                      // UINT32 Size;
    FRAM__NUM_REGIONS,                      // UINT32 NumRegions;
    g_FRAM_BlkRegion,                       // const BlockRegionInfo* pRegions;
};

struct BLOCK_CONFIG g_FRAM_BS_Config =
{
    {
        FRAM__WP_GPIO_PIN,                  // GPIO_PIN Pin;
        FRAM__WP_ACTIVE,                    // BOOL ActiveState;
    },
    &g_FRAM_DeviceInfo,                     // BlockDeviceinfo
};

//--//

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata = "g_FRAM_BS"
#endif

struct BlockStorageDevice g_FRAM_BS;

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata 
#endif 

//--//

